package cn.witsky.rtp2ws.client.ws.netty;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.witsky.rtp2ws.client.ws.ClientListener;
import io.netty.channel.Channel;

public class NettyClient {
	private static  Map<Channel,NettyClient> map=new ConcurrentHashMap<Channel,NettyClient>(2048);
	private  String clientId;
	
	public static NettyClient getNettyClient(Channel channel) {
		if(channel==null) {
			return null;
		}else {
			NettyClient client=map.get(channel);
			return client;
		}

	}
	
	public static void addNettyClient(String clientId,Channel channel) {
		NettyClient client=new NettyClient(clientId,channel);
		map.put(channel, client);
	}
	public static NettyClient reMoveNettyClient(Channel channel) {
		NettyClient client=null;
		if(channel!=null) {
			client=map.remove(channel);
		}
		return client;
	}
	
	private volatile Channel channel;
	private volatile boolean subscribe=true;	
	private ClientListener wsListener;
	
	
	public NettyClient(String clientId,Channel channel) {
		this.clientId=clientId;
		this.channel = channel;
	}
	public Channel getChannel() {
		return channel;
	}
	public boolean isSubscribe() {
		return subscribe;
	}
	public void setSubscribe(boolean subscribe) {
		this.subscribe = subscribe;
	}
	public ClientListener getWsListener() {
		return wsListener;
	}
	public void setWsListener(ClientListener wsListener) {
		this.wsListener = wsListener;
	}

	public String getClientId() {
		return clientId;
	}
	
	
}
